//
//  OPWeatherView.m
//  OnePiece
//
//  Created by wsy on 15/10/31.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPWeatherView.h"

@implementation OPWeatherView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _mainScr = [[UIScrollView alloc]initWithFrame:self.bounds];
        _mainScr.contentSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT*2);
        _mainScr.showsVerticalScrollIndicator = NO;
        _mainScr.pagingEnabled = YES;
        [self addSubview:_mainScr];
        _suggestionLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, SCREEN_WIDTH-80, 300)];
        _suggestionLabel.numberOfLines = 0;
        _suggestionLabel.textColor = [UIColor whiteColor];
        _suggestionLabel.font = [UIFont systemFontOfSize:24];
//        UIButton *xiala = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-20, SCREEN_HEIGHT-50, 40, 40)];
//        xiala.alpha = 0.5;
//        [xiala addTarget:self action:@selector(changeOffset) forControlEvents:(UIControlEventTouchUpInside)];
//        [xiala setImage:[UIImage imageNamed:@"iconfont-iconfontxiangxia"] forState:(UIControlStateNormal)];
//        [_mainScr addSubview:xiala];
        [_mainScr addSubview:_suggestionLabel];
        _placeLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-140, SCREEN_HEIGHT+30, 80, 30)];
        _placeLabel.textAlignment = NSTextAlignmentRight;
        _placeLabel.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_placeLabel];
        _changeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_changeButton setImage:[UIImage imageNamed:@"iconfont-didian"] forState:(UIControlStateNormal)];
        _changeButton.frame = CGRectMake(SCREEN_WIDTH-55, SCREEN_HEIGHT+30, 25, 25);
        [_mainScr addSubview:_changeButton];
        _weatherIcon = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-30, SCREEN_HEIGHT+SCREEN_HEIGHT/4, 60, 60)];
        [_mainScr addSubview:_weatherIcon];
        _tmpLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-20, SCREEN_HEIGHT+SCREEN_HEIGHT/4+60, 60, 40)];
        _tmpLabel.textColor = [UIColor whiteColor];
        _tmpLabel.font = [UIFont systemFontOfSize:24];
        [_mainScr addSubview:_tmpLabel];
        UILabel *nextLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5, 120, 30)];
        nextLabel.text = @"未来四天";
        nextLabel.textColor = [UIColor whiteColor];
        nextLabel.font = [UIFont systemFontOfSize:20];
        [_mainScr addSubview:nextLabel];
        _weatherIcon1 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+50, 30, 30)];
        [_mainScr addSubview:_weatherIcon1];
        _mintmp1 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+100, 50, 30)];
        _mintmp1.textColor = [UIColor whiteColor];
        _mintmp1.font = [UIFont systemFontOfSize:20];
        [_mainScr addSubview:_mintmp1];
        _maxtmp1 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+150, 50, 30)];
        _maxtmp1.font = [UIFont systemFontOfSize:20];
        _maxtmp1.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_maxtmp1];
        _weatherIcon2 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*2-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+50, 30, 30)];
        [_mainScr addSubview:_weatherIcon2];
        _mintmp2 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*2-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+100, 50, 30)];
        _mintmp2.font = [UIFont systemFontOfSize:20];
        _mintmp2.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_mintmp2];
        _maxtmp2 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*2-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+150, 50, 30)];
        _maxtmp2.font = [UIFont systemFontOfSize:20];
        _maxtmp2.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_maxtmp2];
        _weatherIcon3 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*3-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+50, 30, 30)];
        [_mainScr addSubview:_weatherIcon3];
        _mintmp3 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*3-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+100, 50, 30)];
        _mintmp3.font = [UIFont systemFontOfSize:20];
        _mintmp3.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_mintmp3];
        _maxtmp3 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*3-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+150, 50, 30)];
        _maxtmp3.font = [UIFont systemFontOfSize:20];
        _maxtmp3.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_maxtmp3];
        _weatherIcon4 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*4-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+50, 30, 30)];
        [_mainScr addSubview:_weatherIcon4];
        _mintmp4 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*4-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+100, 50, 30)];
        _mintmp4.font = [UIFont systemFontOfSize:20];
        _mintmp4.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_mintmp4];
        _maxtmp4 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/5*4-15, SCREEN_HEIGHT+SCREEN_HEIGHT*3/5+150, 50, 30)];
        _maxtmp4.font = [UIFont systemFontOfSize:20];
        _maxtmp4.textColor = [UIColor whiteColor];
        [_mainScr addSubview:_maxtmp4];
    }
    return self;
}

- (void)setBaseModel:(OPWeatherBaseModel *)baseModel
{
    _placeLabel.text = baseModel.basic[@"city"];
    _weatherIcon.image = [self setImgWithString:baseModel.now[@"cond"][@"txt"]];
    _tmpLabel.text = [NSString stringWithFormat:@"%@°C", baseModel.now[@"tmp"]];
}
- (UIImage *)setImgWithString:(NSString *)str
{
    if ([str containsString:@"云"]) {
        UIImage *image = [UIImage imageNamed:@"iconfont-cloud"];
        return image;
    }else if ([str containsString:@"雨"]){
        UIImage *image = [UIImage imageNamed:@"iconfont-rain"];
        return image;
    }else if ([str containsString:@"雪"]){
        UIImage *image = [UIImage imageNamed:@"iconfont-xue"];
        return image;
    }else{
        UIImage *image = [UIImage imageNamed:@"iconfont-sun"];
    return image;
    }

}

- (void)setNext:(NSArray *)arr
{
    _weatherIcon1.image = [self setImgWithString:arr[0][@"cond"][@"txt_d"]];
    _mintmp1.text = [NSString stringWithFormat:@"%@°C", arr[0][@"tmp"][@"min"]];;
    _maxtmp1.text = [NSString stringWithFormat:@"%@°C", arr[0][@"tmp"][@"max"]];;
    _weatherIcon2.image = [self setImgWithString:arr[1][@"cond"][@"txt_d"]];
    _mintmp2.text = [NSString stringWithFormat:@"%@°C", arr[1][@"tmp"][@"min"]];;
    _maxtmp2.text = [NSString stringWithFormat:@"%@°C", arr[1][@"tmp"][@"max"]];;
    _weatherIcon3.image = [self setImgWithString:arr[2][@"cond"][@"txt_d"]];
    _mintmp3.text = [NSString stringWithFormat:@"%@°C", arr[2][@"tmp"][@"min"]];;
    _maxtmp3.text = [NSString stringWithFormat:@"%@°C", arr[2][@"tmp"][@"max"]];
    _weatherIcon4.image = [self setImgWithString:arr[3][@"cond"][@"txt_d"]];
    _mintmp4.text = [NSString stringWithFormat:@"%@°C", arr[3][@"tmp"][@"min"]];
    _maxtmp4.text = [NSString stringWithFormat:@"%@°C", arr[3][@"tmp"][@"max"]];
}
- (void)setSuggestionModel:(OPWeatherSuggestionModel *)suggestionModel
{
    _suggestionLabel.text = suggestionModel.trav[@"txt"];
}

//- (void)changeOffset
//{
//    [UIView animateWithDuration:1 delay:0 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
//        _mainScr.contentOffset = CGPointMake(0, SCREEN_HEIGHT);
//    } completion:nil];
//}


@end
